package com.etoak.train.controller;

import com.etoak.train.context.LoginMemberContext;
import com.etoak.train.req.PassengerQueryReq;
import com.etoak.train.req.PassengerSaveReq;
import com.etoak.train.resp.CommonResp;
import com.etoak.train.resp.PageResp;
import com.etoak.train.resq.PassengerQueryResp;
import com.etoak.train.service.PassengerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author by 孙有泽
 * @Date 2025/5/10 12:56
 * @Description 旅客controller层
 */
@RestController
@RequestMapping("/passenger")
public class PassengerController {
    @Autowired
    private PassengerService passengerService;

    /*
     * @author 孙有泽
     * @date 2025/5/10 13:08
     * @description 旅客的添加
     */
    @RequestMapping("/save")
    public CommonResp<Object> add(@RequestBody PassengerSaveReq passengerSaveReq){
        passengerService.add(passengerSaveReq);
        return  new CommonResp<>();
    }
    /*
     * @author 孙有泽
     * @date 2025/5/10 19:25
     * @description 根据会员id查询乘车人列表
     */
    @RequestMapping("/query-list")
    public CommonResp<PageResp<PassengerQueryResp>> query(PassengerQueryReq passengerQueryReq){
        passengerQueryReq.setMemberId(LoginMemberContext.getId());
        return new CommonResp<>(passengerService.queryList(passengerQueryReq));
    }
    /*
     * @author 孙有泽
     * @date 2025/5/11 11:39
     * @description 乘坐人的删
     */
    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id){
        passengerService.delete(id);
        return new CommonResp<>();
    }


}
